package com.twu.biblioteca.DAO;

import com.twu.biblioteca.model.Book;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by andreas on 21.04.14.
 */
public class BookDAO {

    private final List<Book> books;

    public BookDAO() {
        books = new ArrayList();
        books.add(new Book(1, "Kent Beck", "Test Driven Development. By Example", false));
        books.add(new Book(2, "Joshua Bloch", "Effective Java", false));
        books.add(new Book(3, "Martin Odersky", "Programming in Scala", true));
    }

    public List<Book> findAvailableBooks() {
        List<Book> availableBooks = new ArrayList();
        for (Book book : books) {
            if (!book.isReserved()) {
                availableBooks.add(book);
            }
        }
        return availableBooks;
    }

    public Book find(int id) {
        for (Book book: books) {
            if (book.getID() == id) {
                return book;
            }
        }
        return null;
    }

    public List<Book> findMyBooks() {
        List<Book> myBooks = new ArrayList();
        for (Book book : books) {
            if (book.isReserved()) {
                myBooks.add(book);
            }
        }
        return myBooks;
    }
}
